<?php

namespace app\zyhsapi\controller\v1;

use app\zyhsapi\controller\ZyhsAuth;
use app\zyhsapi\model\ZyhsMessageCenter;

class System extends ZyhsAuth
{
    public function msgList()
    {
        $page = input('page/d', 1);
        $MsgModel = new ZyhsMessageCenter();

        $uid = $this->user['id'];
        // 获取当前用户的所有消息
        $data = $MsgModel->getUserMsg($uid, 1, $page);
        $tmp = [];
        try
        {
            if ($data['data'])
            {
                foreach ($data['data'] as $k => $v)
                {
                    //反转义
                    $tmp[] = [
                        'id' => (int)$v['id'],
                        'title' => $v['title'],
                        'content' => $v['content'],
                        'create_time' => date('Y.m.d H:i:s', $v['create_time']),
                        'target' => $v['target'],
                        'link' => $v['link']
                    ];
                }
            }
            $data['data'] = $tmp;
        }
        catch (\Exception $e)
        {
            \think\Log::write('获取消息中心列表失败:' . $e->getMessage() . '文件信息:[' . $e->getFile() . $e->getLine() . ']' . '--------用户id:' . $uid, 'log', true);
            $data = [];
        }

        return show(\config('code.success'), '成功', $data);
    }

    public function about()
    {
        $data = [
            [
                'title' => '邮箱',
                'content' => 'help@haozhunapp.com'
            ]
        ];
        return show(config('code.success'), 'Success.', $data);
    }
}
